//供应商网站爬取


<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-row :gutter="22" style="width: 100%;text-align: left;">
          <el-col :span="3" style="margin-left: 10px;margin-top: 10px;">
            <div class="grid-content ep-bg-purple" />已采集供应商
          </el-col>
          <el-col :span="17" style="margin-left:10px;margin-top: 10px;">
            <div class="grid-content ep-bg-purple" />爬虫任务列表
          </el-col>
          <el-col :span="2">
            <div class="grid-content ep-bg-purple" />
            <el-button type="primary" @click="createSplider()"
              style="margin-right: 0;text-align: right;">新建爬虫任务</el-button>
          </el-col>
        </el-row>
        <Diag v-if="showDialog" ref="Diag" :dialog-title="dialogTitle" :item-info="tableItem" @closeDialog="closeDialog">
        </Diag>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <div style="float: left;">
            <el-table :data="tableData">
              <el-table-column prop="name" label="供应商" width="80" />
              <el-table-column prop="address" label="域名链接" width="150" />
            </el-table>

          </div>

        </el-aside>
        <el-main>


          <div v-for="(item, index) in items" style="margin-top:10px;" v-bind:key="index">
            <Listvue
             :item="item"
             :options="options"
             :index="index"
             @deletS="taskDelete"
             :submitUrl="submitUrl"
             />

          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>


<script>
import Listvue from '../../components/List.vue';
import Diag from '../../components/Diag.vue';


export default {
  name: "SupplierWeb",
  data() {
    return {
      tableLoading: false,
      showDialog: false,
      dialogTitle: "新增爬虫任务",
      tableItem: {
        commitUrl: '/api/keywords/startTask', //提交给后端的路径 和参数
        userID: '1',
        crawlerType:'keywords'
      },
      submitUrl:{
        pauseUrl:'/api/keywords/pauseTask',  //暂停提交的url
        deleteUrl:'/api/keywords/stopTask',
        logUrl:'/api/supplier/logging'
      },
      items: [],
      options: {
        optionsRenew: [
          {
            value: '全量',
            label: '全量模式',
          },
          {
            value: '增量',
            label: '增量模式',
          },

        ],
        optionsPriority: [{
          value: '低',
          label: '低',
        },
        {
          value: '中',
          label: '中',
        },
        {
          value: '高',
          label: '高',
        }]
      },
      tableData: [
       
      ]
    }
  },
  components: {
    Listvue,
    Diag
  },
  mounted() {
    
    this.get('/api/keywords/getTasks')
  },

  methods: {
    createSplider() {
      this.tableItem = {};
      this.dialogTitle = "新增爬虫任务";
      this.showDialog = true;
      this.$nextTick(() => {
        this.$refs["Diag"].showDialog = true;
      });
      console.log(this.$refs["Diag"]);

    },
    checkLog() {
      console.log("查看更新日志")
    },
    //打开添加用户弹窗
    taskDelete(){  //通过操作下表操作数组不能做到响应式 那么只能通过后端请求数据刷新页面 在下面用axios再调用一次接口即可
      this.get('/api/supplier/stopTask')

  },
  async get(url) {  //async  await  是解决异步的一种方案，必须要加，但是原生封装就不用
      this.$axios.get(url, {
            params: {
                userID: 1
            }
        }).then((res) => {
            console.log(res.data);
            this.items=res.data.data
            console.log('this.items',this.items);
        })

    }
}
}
</script>

<style>
.outdiv {
  display: flex;
  width: 100%;
}

.card-header {
  width: 100%;
  height: 200px;
  font-size: 15px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
}

.m-2 {
  width: 60%;
}

.a {
  float: left;
  color: goldenrod;
}

.b {
  float: left;
  color: red;
}</style>
